<!DOCTYPE html>
<html lang="zh-cmn-Hans">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <link rel="stylesheet" href="../../static/assets/css/zpui.css" />
    <link rel="stylesheet" href="../../static/assets/css/all.css" />
     <link rel="stylesheet" href="../../static/mobile/default/css/layout.css?v=2" />
    <script src="../../static/assets/js/page.js"></script>
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>

    <title> 可用余额提现 </title>
</head>

<body>
    <div class="page">
        <div class="page-hd">
            <div class="header bor-1px-b">
                <div class="header-left">
                    <a href="../../member/center/index.html" class="left-arrow"></a>
                </div>
                <div class="header-title">可用余额提现</div>
                <div class="header-right">
                    <a href="#"></a>
                </div>
            </div>
        </div>

        <div class="page-bd">
            <!-- 页面内容-->
            <div class="weui-cells card-box">
                <div class="weui-cell weui-cell_access">
                                        <div class="weui-cell__bd" >
                    <!--<div class="weui-cell__bd" onclick="gourl()">-->
                                                <div class="fs26 fw600">微信（<span  id="realName"></span>）</div>
                                            </div>
                    <!--<div class="weui-cell__ft"></div>-->
                </div>
            </div>
            <div class="weui-cells card-box">
                <div class="weui-cell">
                    <div class="weui-cell__bd">
                        <div>
                            <span class="fs28 fw600 mr10">提现金额</span>
                            <span class="fs22 text-muted">可提现金额 ¥<span class="allProfit">0</span> </span>
                        </div>
                        <div class="tx_input mt20">
                            <img src="../../static/assets/images/icon_money.png" alt="">
                            <input class="weui-input"  id="number" type="number" placeholder="请输入金额" value=""  oninput="numberVal()">
                        </div>
                        <div class="fs24 mt20 fw600">税率：7%，扣除税费：<b id="number_val">0</b> 元</div>
                    </div>
                </div>
            </div>
            <div class="weui-btn-area">
                <a href="javascript:;" onclick="checkWithdraw()" class="weui-btn weui-btn_primary">确认提现</a>
            </div>
            <div class="weui-btn-area">
                <img src="../../static/assets/images/wenx1.png" width="100%" style="margin-top:50px">
            </div>
        </div>
    </div>

    <div class="alertBox">
        <div class="alertBG"></div>
        <div class="alert">
            <div class="text fs30 color_3 bor_b">

            </div>
            <!-- 单按钮 -->
            <div class="button fs32 fw_b color_r">
                知道了
            </div>
            <!-- 双按钮 -->
            <div class="buttonBox fs32 fw_b">
                <span class="color_9 bor_r cancel">取消</span>
                <span class="color_r confirm">确定</span>
            </div>
        </div>
    </div>
    <script src="../../static/assets/js/lib/jquery-2.1.4.js"></script>
    <script src="../../static/assets/js/jquery-weui.min.js"></script>
     <script src="../../static/js/jquery/jquery.cookie.js"></script>
    <script src="../../static/assets/js/lib/fastclick.js"></script>
    <script src="../../static/mobile/default/js/page.js?v=1"></script>
    <script>
     var allProfit = 0
          share()
     function  share(){
    /***用户点击分享到微信圈后加载接口接口*******/
        var url=window.location.href;
        console.log("url:"+url);
            $.ajax({
		    url: "/api/mp/wxconfig",
		    type: "post",
		    data:{shareUrl:url},
		    headers:{ token: $.cookie('code')},
		    dataType: "json",
		    success: function(data){
		         configData = {
                    debug : false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                    appId: data.data.appid, // 必填，公众号的唯一标识
                    timestamp: data.data.timestamp, // 必填，生成签名的时间戳
                    nonceStr: data.data.nonceStr, // 必填，生成签名的随机串
                    signature: data.data.signature,// 必填，签名，见附录1
                    jsApiList : ['hideOptionMenu']
                    // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
               };
               
               //step2:注入配置信息
               wx.config(configData);
               //step3:通过ready接口处理成功验证
               wx.ready(function () {
                   // config信息验证后会执行ready方法，所有接口调用都必须在config接口获得结果之后，config是一个客户端的异步操作，所以如果需要在页面加载时就调用相关接口，则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口，则可以直接调用，不需要放在ready函数中。
//                 alert("执行ready方法");
//                 wx.checkJsApi({
//                      jsApiList: ['chooseImage'] // 需要检测的JS接口列表，所有JS接口列表见附录2,
//                      success: function(res) {
//                      // 以键值对的形式返回，可用的api值true，不可用为false
//                      // 如：{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
//                      }
//                 });
                   //接口1:获取网络类型
                    wx.getNetworkType({
                        success: function (res) {
                          oldNet = res.networkType; // 返回网络类型2g，3g，4g，wifi
//                        alert("网络类型"+ oldNet);
                        }
                     });
                   //禁用右上角菜单按钮
                   wx.hideOptionMenu();
		    })
		    },
		    error: function() {
// 			    _alert('ajax request failed!!!!');
			    return;
		    } 
        })

	    
	    
	    }
	    
	    var free  = 0
	    
	    function numberVal(){
	        
	            var num =  Number( $('#number').val() ? $('#number').val() :0)*0.07
	            $('#number_val').text(Math.round(num));
	            free = Math.round(num)
	    }
        $(function() {
            FastClick.attach(document.body);
	    
	        
                        getUserInfo()
                 
                    //获取用户信息
                    function getUserInfo() {
                        var test = $.cookie('code')
                        console.log(test)
                        $.ajax({
                            url: 'https://mp.jianguoes.com/api/mp/getUserInfo',// 跳转到 action
                            data: {},
                            type: 'get',
                            headers:{ token: $.cookie('code')},
                            dataType: 'json',
                            success: function (res) {
                                console.log(res);
                                if (res.errno == 0) {
                                    
                                    if(res.data.isReal ==1){
                                          _alert('请先实名认证',function(){
         
                                                window.location.href = './contract/auth.html'
                                            });
                                            setTimeout(function() {
                                                window.location.href ='./contract/auth.html'
                                            }, 2000);
                                    }
                                    $('#realName').text(res.data.realName)
                                    $('.allProfit').text(res.data.mlsuser.allProfit)
                                    allProfit=res.data.mlsuser.allProfit
                                    
                                }

                            }, error: function () {

                            }
                        });
                    }
        });
    </script>
    <script>
        var number = 0;
        var account_id = "45";
        var account_type = "weixin";
        var phone = "13022099392";
        if (!phone) {
            $.alert('请先绑定手机号',function(){
                window.location.href = "./bindphone.html";
            })
        }
        function gourl() {
            window.location.href = "../../member/withdraw/banklist.html?number=" + number + "&account_id=" + account_id
        }

        function checkWithdraw() {
            if (!account_id) {
                $.alert('你还没提现账户',function(){
                    window.location.href = "../../member/withdraw/banklist.html?number=" + number + "&account_id=" + account_id
                })
                return;
            }
            number = $('#number').val();
            if(!number){
                _alert('请输入金额')
                return false
            }else if(number<100){
                _alert('提现最低金额为100')
                return false
            }else if(number>allProfit){
                _alert('最高不能超过可用余额')
                return false
            }else{
               _alert('确定要提现吗？',function(){
                   $.ajax({
                            url: '/api/mp/withdrawCashes',// 跳转到 action
                            data: {amount: number},
                            type: 'post',
                            headers:{ token: $.cookie('code')},
                            dataType: 'json',
                            success: function (res) {
                                console.log(res);
                                if (res.errno == 0) {
                                    var money = Number(number)-Number(free)
                                  window.location.href ='./withdrawSuccess.html?money='+money+'&free='+free
                                    
                                }else{
                                    _alert(res.errmsg)
                                }

                            }, error: function () {

                            }
                        });
               })
            }
            
            
 
        }

        //提交提现
        function enterWithdraw() {
            number = $('#number').val();
            $.post("/member/api.withdraw/postwithdraw.html", {
                amount: number,
                account_type: account_type,
                account_id: account_id
            }, function(data) {
                if (data.code == 0) {
                    $.alert(data.msg);
                    return false;
                } else {
                    $.alert(data.msg, function() {
                        window.location.href = "./myassets.html"
                    });

                }
            })
        }
        // withdraw_fee();

        function withdraw_fee() {
            number = $('#number').val();
            $.post("/member/api.withdraw/checkwithdraw.html", {
                amount: number,
                isreturn: false,
                noreturn: true
            }, function(data) {
                $('#number_val').text(data)
            })
        }
    </script>
</body>

</html>